home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / pc / files / t_unix / bs941029.tgz / bbsx-941029.tar / bbsx / bbs_main.c < prev    next >
C/C++ Source or Header  |  1994-10-29  |  4KB  |  183 lines

  1. static char rcsid[] = "@(#) $Header: /home/dg1rtf/tcp/bbsx/RCS/bbs_main.c,v 1.2 1994/10/29 15:18:25 root Exp $";
  2.  
  3. #define _HPUX_SOURCE
  4.  
  5. #include <sys/types.h>
  6.  
  7. #include <stdio.h>
  8.  
  9. #include <ctype.h>
  10. #include <pwd.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <signal.h>
  14. #include <termios.h>
  15. #include <fcntl.h>
  16. #include <time.h>
  17.  
  18. #include "bbs.hd"
  19. #include "bbs.h"
  20.  
  21. /*---------------------------------------------------------------------------*/
  22.  
  23. int main (int argc, char **argv)
  24. {
  25.  
  26.   char *cp;
  27.   char *dir = WRKDIR;
  28.   char *sysname;
  29.   char buf[1024];
  30.   int c;
  31.   int err_flag = 0;
  32.   struct passwd *pw;
  33.   static struct termio save;
  34.   struct tm *tm;
  35.   long now;
  36.   char logfile[80];
  37.   struct log log;
  38.         
  39.   now = time(0L);
  40.   tm=gmtime(&now);
  41.   sprintf(logfile,"%s%02d%02d.log",LOGFILE,tm->tm_year, tm->tm_mon);
  42.               
  43.  
  44.   ioctl(0,TCGETA,&save);
  45.   orig_escape = save.c_cc[VINTR];
  46.   escape_char = orig_escape;
  47.   
  48.   signal(SIGINT,  interrupt_handler);
  49.   signal(SIGQUIT, interrupt_handler);
  50.   signal(SIGALRM, alarm_handler);
  51.  
  52.   umask(022);
  53.  
  54.   sscanf(rcsid, "%*s %*s %*s %s %s %s %s %s",
  55.         revision.number,
  56.         revision.date,
  57.         revision.time,
  58.         revision.author,
  59.         revision.state);
  60.   
  61.   if (chdir(dir)) {
  62.     mkdir(dir, 0755);
  63.     if (chdir(dir)) halt();
  64.   }
  65.   read_config();
  66.  
  67.  
  68. #ifdef BOXBIN  
  69.   init_crc();
  70. #endif  
  71.  
  72.   bbs_adm = getpwnam(bbsadm);
  73.   is_bbs_adm = (bbs_adm->pw_uid == getuid());
  74.   
  75.   pw = getpwnam(telluser);
  76.   is_tell_user = (pw->pw_uid == getuid());
  77.   
  78.   while ((c = getopt(argc, argv, "df:mpw:")) != EOF)
  79.     switch (c) {
  80.     case 'd':
  81.       debug = 1;
  82.       break;
  83.     case 'f':
  84.       if (getuid() && !is_bbs_adm) {
  85.     puts("The 'f' option is for Store&Forward use only.");
  86.     exit(1);
  87.       }
  88.       sysname = optarg;
  89.       mode = BBS;
  90.       doforward = 1;
  91.       break;
  92.     case 'm':
  93.       mode = MAILorNEWS;
  94.       break;
  95.     case 'p':
  96.       packetcluster = 1;
  97.       break;
  98.     case 'w':
  99.       sleep(atoi(optarg));
  100.       break;
  101.     case '?':
  102.       err_flag = 1;
  103.       break;
  104.     }
  105.   if (optind < argc) err_flag = 1;
  106.   if (err_flag) {
  107.     puts("usage: bbs [-d] [-w seconds] [-f system|-m]");
  108.     exit(1);
  109.   }
  110.   if (!getcwd(buf, sizeof(buf))) halt();
  111.   user.cwd = strdup(buf);
  112.  
  113.   if (gethostname(buf, sizeof(buf))) halt();
  114.   if (cp = strchr(buf, '.')) *cp = 0;
  115.  
  116.   pw = doforward ? getpwnam(sysname) : getpwuid(getuid());  
  117.  
  118.   if (!pw) halt();
  119.   user.name = strdup(pw->pw_name);
  120.   if (!strcmp(user.name,"root") || (is_bbs_adm && !doforward)) { 
  121.     strcpy(user.name,myhostname);
  122.     strlwc(user.name);
  123.   }  
  124.   user.uid = pw->pw_uid;
  125.   user.gid = pw->pw_gid;
  126.   user.dir = strdup(pw->pw_dir);
  127.   user.shell = strdup(pw->pw_shell);
  128.   endpwent();
  129.   if (!user.uid || is_bbs_adm) level = ROOT;
  130.   if (is_bbs_adm && !doforward) level = ROOT;
  131.   if (connect_addr(user.name)) level = MBOX;
  132.   if (level != MBOX) init_aliasdb();
  133.   if (!getenv("LOGNAME")) {
  134.     sprintf(buf, "LOGNAME=%s", user.name);
  135.     putenv(strdup(buf));
  136.   }
  137.   if (!getenv("HOME")) {
  138.     sprintf(buf, "HOME=%s", user.dir);
  139.     putenv(strdup(buf));
  140.   }
  141.   if (!getenv("SHELL")) {
  142.     sprintf(buf, "SHELL=%s", user.shell);
  143.     putenv(strdup(buf));
  144.   }
  145.   if (!getenv("PATH"))
  146.     putenv("PATH=/bin:/usr/bin:/usr/contrib/bin:/usr/local/bin");
  147.   if (!getenv("TZ"))
  148.     putenv("TZ=MEZ-1MESZ");
  149.  
  150.   if(!getenv("EDITOR")) {
  151.     putenv("EDITOR="EDITOR);
  152.     strcpy(editor,EDITOR);
  153.   }  
  154.   else
  155.    strcpy(editor,getenv("EDITOR"));
  156.    
  157.   if (level != MBOX)
  158.     get_seq();
  159.   
  160.   if (level == MBOX)
  161.     binary_allowed = 0;
  162.  
  163.   while (!(fdindex = open(INDEXFILE, O_RDWR | O_CREAT, 0644))) ;
  164.   if (fdindex < 0) halt(); 
  165.  
  166.   if (log_reading && level == USER)
  167.      if ((fdlog = open(logfile, O_RDWR | O_CREAT, 0644)) <= 0) halt();
  168.   
  169.   lowest_on_start = get_lowest_on_start();
  170.   highest_on_start = get_highest_on_start();
  171.  
  172.   switch (mode) {
  173.   case BBS:
  174.     bbs();
  175.     break;
  176.   case MAILorNEWS:
  177.     recv_from_mail_or_news();
  178.     break;
  179.   }
  180.   return 0;
  181. }
  182.  
  183.